<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // js 中提供了三种方法改变函数内部的this指向，分别是call(),bind(),apply()
    // call(thisobj,arg1,arg2,arg3)

    // 1.改变命名函数中的this指向
    function f(a, b) {
        console.log(this)
    }

    obj = {
        "name": "周文军"
    };

    f(1, 2);
    f.call(obj, 1, 3);

    console.log("=======================");

    // 2.call的主要作用是实现继承
    function Father(name, age) {
        this.name = name;
        this.age = age;
    }

    Father.prototype.sing = function () {
        console.log("Father's sing");
        console.log(this.name);  // biber
    };

    function Son(name, age) {
        Father.call(this, name, age);
    }

    Son.prototype = new Father();
    Son.prototype.constructor = Son;
    Son.prototype.study = function () {
        console.log("Son's study")
    };

    var son = new Son("biber", 18);
    console.log(son);
    son.study();
    son.sing();


</script>
</body>
</html>